<?php

namespace common\models;


use yii\db\ActiveRecord;

class ShopCollection extends ActiveRecord
{
    public static function tableName()
    {
        return 'shop_collection';
    }

    public function rules()
    {
        return [
            [['id','shop_id','goods_id','status','is_del','create_time','update_time'],'integer'],

        ];
    }

    public function attributeLabels()
    {
        return [
            'id	'=>'id',
            'shop_id'=>'用户id',
            'goods_id'=>'内容id',
            'status'=>'状态类型',
            'is_del'=>'是否删除',
            'create_time'=>'创建时间',
            'update_time'=>'更新时间'
        ];
    }

    /**
     * 添加收藏
     * @param $data
     * @return bool
     */
    public static function addCollection($data){
        //先查找是否有
        $row = self::find()->where([
            'shop_id' => $data['shop_id'],
            'goods_id' => $data['goods_id'],
            'status' => $data['status'],
            'is_del' => 0,
        ])->one();
        if(!empty($row)){
            $row['update_time'] = $data['update_time'];
            return $row->save();
        }
        $Model = new self();

        $Model->setAttributes($data);
        if($Model->save()){
            return true;
        }
        return false;
    }

}